package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"qq_service/server/base/msg_queue/rabbit/lib"
	"qq_service/server/models"
	"time"
)

var mq *lib.MQ

func init() {
	var err error
	mq, err = lib.MQInit()
	if err != nil {
		log.Fatal(err)
	}
}

func FindQQByQun(c *gin.Context) {
	qq := models.QQ{}
	err := c.BindJSON(&qq)
	if err != nil {
		c.JSON(400, gin.H{"result": "error" + err.Error()})
	} else {

		uid := time.Now().Local()
		//mq.SetConfirm()
		mq.NotifyReturn()
		err := mq.SendMessage(lib.RouterKeyUserReg, lib.ExchangeUser, qq.QQ)
		//err := mq.SendDelayedMessage(lib.RouterKeyUserReg, lib.ExchangeUserDelayed, fmt.Sprintf("%d", uid), 1000)
		if err != nil {
			fmt.Println(err)
			return
		}
		//mq.ListenConfirm()
		c.JSON(200, gin.H{"result": uid})
	}

}
